package com.horoscope.astrology.zodiac.signs.free.activity

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.horoscope.astrology.zodiac.signs.free.AppSettingManager
import com.horoscope.astrology.zodiac.signs.free.MmoConstant
import com.horoscope.astrology.zodiac.signs.free.R
import com.horoscope.astrology.zodiac.signs.free.bean.UserBean
import com.horoscope.astrology.zodiac.signs.free.utils.EventType
import com.horoscope.astrology.zodiac.signs.free.utils.FlurryEventUtil

class StartActivity : BaseActivity() {

    private var mUserBean: UserBean? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_start)
        mUserBean = AppSettingManager.readObject("user_info")

        // 第一页显示出来只打一次
        FlurryEventUtil.putDataToEvent(EventType.TYPE_WELCOME_SHOW, null, null)
    }

    private fun next() {
        if (mUserBean == null) {
            val intent = Intent(this@StartActivity, PreMainActivity::class.java)
            startActivity(intent)
        } else {
            val intent = Intent(this@StartActivity, MainActivity::class.java)
            startActivity(intent)
        }
        finish()
    }

    fun ppOnClick(view: View) {
        val intent = WebViewActivity.generateWebViewIntent(
            this@StartActivity,
            MmoConstant.POLICY_URL,
            false,
            getString(R.string.text_privacy_policy)
        )
        startActivity(intent)
    }

    fun tuOnClick(view: View) {
        val intent = WebViewActivity.generateWebViewIntent(
            this@StartActivity,
            MmoConstant.TERMS_URL,
            false,
            getString(R.string.text_terms)
        )
        startActivity(intent)
    }

    fun okOnClick(view: View) {
        // 在该页点击了按钮只打一次
        FlurryEventUtil.putDataToEvent(EventType.TYPE_SPLASH_WELCOME_CONTINUE, null, null)
        next()
    }
}